package com.dyh.quickdemozwei.deliver.state;



import com.dyh.quickdemozwei.deliver.DeliverCommonDomain;
import com.dyh.quickdemozwei.deliver.ManyManyReference;
import com.dyh.quickdemozwei.deliver.OneManyReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class QueryPkgInfoState implements DeliverState{

    protected Map<String, DeliverCommonDomain.Pkg> pkgMap;
    protected Map<String, DeliverCommonDomain.PkgDetail> pkgDetailMap;
    protected OneManyReference pkg2PkgDetailRef;
    protected ManyManyReference pkg2ogRef;



    List<DeliverCommonDomain.Pkg> pkgList;
    List<DeliverCommonDomain.PkgDetail> pkgDetails;

    public void input(List<DeliverCommonDomain.Pkg> pkgList,
                      List<DeliverCommonDomain.PkgDetail> pkgDetails
    ){
       this.pkgList = pkgList;
       this.pkgDetails = pkgDetails;
    }

    @Override
    public DeliverState trick() {
        for (DeliverCommonDomain.Pkg pkg : this.pkgList) {
            this.pkgMap.put(pkg.getId(),pkg);
        }

        for (DeliverCommonDomain.PkgDetail pkgDetail : this.pkgDetails) {
            this.pkg2PkgDetailRef.updateByAuto(pkgDetail.getPkgId(),pkgDetail.getId());

            this.pkg2ogRef.updateByAuto(pkgDetail.getPkgId(),pkgDetail.getOgId());

            this.pkgDetailMap.put(pkgDetail.getId(),pkgDetail);
        }

        return null;
    }
}
